﻿using System;
using System.Runtime.Serialization;
using Microsoft.Xna.Framework;

namespace DKE_Kinect.Entwicklung.PolyVox
{
    /// <summary>
    /// Actions for a Voxel
    /// </summary>
    public enum VoxelAction
    {
        /// <summary>
        /// Set a single voxel
        /// </summary>
        set,
        /// <summary>
        /// sets a sphere around this voxel
        /// </summary>
        sphere,
        /// <summary>
        /// set this voxel as a part of a line
        /// </summary>
        line,
        /// <summary>
        /// set this voxel as a edge of a block
        /// </summary>
        block
    }
    [Serializable()]
    class VoxelStruct : ISerializable
    {
       
        private Vector3 pPosition;
        private byte pColor;
        private byte pDenstity;
        private VoxelAction pAction;
        private int pRadius;

        public byte Color
        {
            get { return pColor; }
        }
        public byte Density
        {
            get { return pDenstity; }
        }
        public Vector3 Position
        {
            get { return this.pPosition; }
        }
        public VoxelAction Action
        {
            get { return pAction; }
        }
        public int Radius
        {
            get { return pRadius; }
        }

   
        public VoxelStruct(Vector3 position, PolyVoxCore.MaterialDensityPair62 voxel,VoxelAction action)
        {
            pPosition = position;
            pColor = voxel.getMaterial();
            pDenstity = voxel.getDensity();
            pAction = action;
            pRadius = 0;
        }
 
        public VoxelStruct(Vector3 position, PolyVoxCore.MaterialDensityPair62 voxel, int radius,VoxelAction action)
        {
            pPosition = position;
            pColor = voxel.getMaterial();
            pDenstity = voxel.getDensity();
            pAction = action;
            pRadius = radius;
        }
        #region ISerializable Member
        public VoxelStruct(SerializationInfo info, StreamingContext context)
        {
            pPosition = (Vector3)info.GetValue("position", typeof(Vector3));
            pColor = (byte)info.GetValue("material", typeof(byte));
            pDenstity = (byte)info.GetValue("density", typeof(byte));
            pRadius = (int)info.GetValue("radius", typeof(int));
            pAction = (VoxelAction)info.GetValue("action", typeof(VoxelAction));
          

        }
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("position", pPosition);
            info.AddValue("material",pColor);
            info.AddValue("density", pDenstity);
            info.AddValue("radius", pRadius);
            info.AddValue("action", pAction);
        }

        #endregion


    }
}
